#!/usr/bin/env python

#retrieves undeleted calendar events from the iphone image dump

import sqlite3

from time import strftime, localtime, gmtime
def run(s):
	#check if the file calendar.sqlitedb is there
	#try:
		print('Found "{}"'.format(s))
		#connect to the db

		conn = sqlite3.connect(s)
		c = conn.cursor()
		#print the column headers

		#get the table to print
		for  ROWID, summary,location,description,start_date,end_date,all_day in c.execute('select ROWID, summary,location,description,start_date,end_date,all_day from Event'):
			
			row = str(ROWID)
			startDate = strftime('%Y-%m-%d %H:%M:%S (%Z)', localtime(start_date+978307200))
			endDate = strftime('%Y-%m-%d %H:%M:%S (%Z)', localtime(end_date+978307200))
			#prints the values
			print('{0:10}{1:10}{2:20}{3:20} {4:30} {5:30} {6:30}'.format( row, summary,location,description,startDate,endDate,all_day ))

		#endofloop
			
	# except sqlite3.Error:
	# 	print('The notes.db is not placed in the current working directory')   

	

def main():
	#execute the operation on the sms.db file
	
	databaseName = 'Calendar.sqlitedb'
	run(databaseName)

#exec main
if __name__ == '__main__':
	main()